package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper {
    @Select("select * from address_book where user_id = #{userId}")
    List<AddressBook> findAllByUserId(Long userId);

    @Update("update address_book set is_default = 0")
    void setDefault();

    /**
     * 修改地址
     * @param addressBook
     */
    void update(AddressBook addressBook);

    /**
     * 根据id查询地址
     * @param id
     * @return
     */
    @Select("select * from address_book where id = #{id}")
    AddressBook getAddressBookById(Long id);

    @Insert("insert into address_book values (null, #{userId}, #{consignee}, #{sex}, #{phone}, " +
            "#{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}, #{districtCode}, #{districtName}," +
            " #{detail}, #{label}, #{isDefault})")
    void save(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void delete(Integer id);
}
